import { request } from '@/service'

interface ResultType {
  result: {
    resultCode: string
    resultMessage: string
  }
  data: object
}

/** 适配接口返回结果 */
function adapter(obj: ResultType) {
  if (obj.result?.resultCode === '000000') {
    return obj.data
  }
  throw new Error('错误')
}

/** 项目用能管理 start */
//查询用能项目信息列表
export const queryYnxmxxInfoList = (params?: any) =>
    request.get('/ynxmxx/queryYnxmxxInfoList', { params }).then((res: any) => adapter(res))

//查询节能项目信息列表
export const queryJnXmInfoList = (params?: any) =>
    request.get('/ynxmxx/queryJnXmInfoList', { params }).then((res: any) => adapter(res))

//根据项目id查询用能项目信息
export const queryYnxmxxInfo = (params?: any) =>
    request.get('/ynxmxx/queryYnxmxxInfo', { params }).then((res: any) => adapter(res))

//新增或修改用能项目信息
export const ynxmxxInsertOrUpdate = (data?: any) =>
    request.post('/ynxmxx/insertOrUpdate', data).then((res: any) => adapter(res))

//查询项目名称字典
export const queryXmmcInfoList = (data?: any) =>
    request.get('/zd/queryXmmcInfoList', data).then((res: any) => adapter(res))
    
//查询企业信息 包含ID
export const queryQyxxInfoList = (data?: any) =>
request.get('/qyxx/queryQyxxInfoList', data).then((res: any) => adapter(res))

